<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

// 商品列表
Route::redirect('/', '/products')->name('root');
// 商品列表
Route::get('products', [App\Http\Controllers\ProductsController::class,'index'])->name('products.index');
// 商品详情
Route::get('products/{product}', [App\Http\Controllers\ProductsController::class,'show'])->name('products.show');
Auth::routes();
Route::get('welcome', [App\Http\Controllers\HomeController::class,'index']);

Route::group(
    ['middleware' => 'auth'],
    function () {
    	// 收藏商品
        Route::post('products/{product}/favorite', 'App\Http\Controllers\ProductsController@favor')->name('products.favor');
        // 取消收藏
        Route::delete('products/{product}/favorite', 'App\Http\Controllers\ProductsController@disfavor')->name('products.disfavor');
        // 收藏列表
        Route::get('product/favorites', 'App\Http\Controllers\ProductsController@favorites')->name('products.favorites');
            // 购物车列表
        Route::get('carts', 'App\Http\Controllers\CartsController@index')->name('carts.index');
        // 加入购物车
        Route::post('carts', 'App\Http\Controllers\CartsController@store')->name('carts.store');
        // 移除购物车
        Route::delete('carts/{sku}', 'App\Http\Controllers\CartsController@destroy')->name('carts.destroy');
        // 订单管理-众筹商品创建订单
        Route::post('crowdfunding_orders', 'OrdersController@crowdfunding')->name('crowdfunding_orders.store');
        // 订单管理-秒杀商品创建订单
Route::post('seckill_orders', 'OrdersController@seckill')->name('seckill_orders.store')->middleware('random_drop:20');
      // 用户地址信息
        Route::resource('user_addresses', 'App\Http\Controllers\UserAddressesController');
              // 订单管理-订单列表
        Route::get('orders', 'App\Http\Controllers\OrdersController@index')->name('orders.index');
        // 订单管理-创建订单
        Route::post('orders', 'App\Http\Controllers\OrdersController@store')->name('orders.store');
        // 订单管理-订单详情
        Route::get('orders/{order}', 'App\Http\Controllers\OrdersController@show')->name('orders.show');
           // 订单管理-订单关闭
        Route::get('orders/{order}/closed', 'App\Http\Controllers\OrdersController@closed')->name('orders.closed');
        // 订单管理-确认发货
        Route::post('orders/{order}/received', 'App\Http\Controllers\OrdersController@received')->name('orders.received');
        // 订单管理-评价商品
        Route::get('orders/{order}/review', 'App\Http\Controllers\OrdersController@review')->name('orders.review.show');
        // 订单管理-发送评价
        Route::post('orders/{order}/review', 'App\Http\Controllers\OrdersController@sendReview')->name('orders.review.store');
        // 订单管理-申请退款
        Route::post('orders/{order}/apply_refund', 'App\Http\Controllers\OrdersController@applyRefund')->name('orders.apply_refund');
        
        //支付跳过
        Route::get('payment/{order}/test', 'App\Http\Controllers\PaymentController@test')->name('payment.test');
                // 订单支付-支付宝支付
        Route::get('payment/{order}/alipay', 'App\Http\Controllers\PaymentController@payByAliPay')->name('payment.alipay');
        // 订单支付-支付宝支付前端回调页面
        Route::get('payment/alipay/return', 'App\Http\Controllers\PaymentController@alipayReturn')->name('payment.alipay.return');
        // 订单支付-服务器回调
Route::post('payment/alipay/notify', 'App\Http\Controllers\PaymentController@alipayNotify')->name('payment.alipay.notify');
        // 订单支付-微信支付
        Route::get('payment/{order}/wechat', 'App\Http\Controllers\PaymentController@payByWechatPay')->name('payment.wechat');
        // 订单支付-微信支付前端回调页面
        Route::post('payment/wechat/notify', 'App\Http\Controllers\PaymentController@wechatNotify')->name('payment.wechat.notify');
    	}
);
